#include "pch.h"
#include "SameAirplanLoadingClr.h"
#include "DataTransform.h"

namespace LoadingWK
{
    SameAirplanLoadingClr::SameAirplanLoadingClr()
    {
        _pIntelligentLoad = new gaeaway_load::LoadingBySameKindAirPlane();
    }
    SameAirplanLoadingClr::~SameAirplanLoadingClr()
    {
        if (nullptr != _pIntelligentLoad)
        {
            delete _pIntelligentLoad;
            _pIntelligentLoad = nullptr;
        }
    }

    bool SameAirplanLoadingClr::importInformationOfEquipments(Generic::List<LoadingWK::EquipmentClr^>^ pEquipmentList)
    {
        return _pIntelligentLoad->importEquipments(DataTransformCLR::transformToEquipmentsOfInput(pEquipmentList));
    }

    bool SameAirplanLoadingClr::importInformationOfAirplane(LoadingWK::AirplaneClr^ airplane, Double minSpacing)
    {
        _pIntelligentLoad->importAirplane(DataTransformCLR::transformToAirplane(airplane), minSpacing);
        return true;
    }

    System::Double SameAirplanLoadingClr::getStepOfOffsetLoad()
    {
        return _pIntelligentLoad->getStepOfOffsetLoad();
    }

    void SameAirplanLoadingClr::setStepOfOffsetLoad(Double step)
    {
        _pIntelligentLoad->setStepOfOffsetLoad(step);
    }

    int SameAirplanLoadingClr::startLoadingWithMaxCountOfAirplane(int maxCountOfAirplane)
    {
        _pIntelligentLoad->startLoadingByMaxCount(maxCountOfAirplane);
        return _pIntelligentLoad->getCountOfLoadedAirplanes();
    }

    int SameAirplanLoadingClr::startLoadingWithoutLimit()
    {
        _pIntelligentLoad->startLoadingWithoutLimit();
        return _pIntelligentLoad->getCountOfLoadedAirplanes();
    }
    LoadingWK::LoadedEquipmentListClr^ SameAirplanLoadingClr::getLoadedEquipments()
    {
        LoadingWK::LoadedEquipmentListClr^ pEquipmentList = gcnew LoadingWK::LoadedEquipmentListClr();

        gaeaway_load::EquipmentsOfOutput result = _pIntelligentLoad->getLoadedEquipments();
        for (auto ver : result)
        {
            LoadingWK::LoadedEquipmentClr^ equipment =
                gcnew LoadingWK::LoadedEquipmentClr(ver.equipmentID, ver.airplaneKindID, ver.loadedAirplanIndex, ver.leftY);

            pEquipmentList->addEquipment(equipment);
        }
        return pEquipmentList;
    }
    System::Collections::Generic::List<LoadingWK::LoadedAirplaneClr^>^ SameAirplanLoadingClr::getLoadedAirplanes()
    {
        return DataTransformCLR::transformToLoadedAirplaneClrs(_pIntelligentLoad->getLoadedAirplanes());
    }

    System::Collections::Generic::List<LoadingWK::EquipmentClr^>^ SameAirplanLoadingClr::getUnloadedEquipments()
    {
        gaeaway_load::EquipmentsOfInput unloadedEquipments = _pIntelligentLoad->getUnloadedEquipments();
        Generic::List<LoadingWK::EquipmentClr^>^ results = gcnew Generic::List<LoadingWK::EquipmentClr ^>(0);
        for (auto equipment : unloadedEquipments)
        {
            results->Add(DataTransformCLR::transformToLoadingEquipment(equipment));
        }
        return results;
    }

}